

import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;

public class CalculPi extends UnicastRemoteObject implements CalculPiInterface {

	private int monKaAMoi;
	private int N;
	private int n;
	
	public CalculPi(int k, int N, int n) throws RemoteException{
		this.monKaAMoi = k;
		this.N = N;
		this.n = n;
	}

	public float calcul() throws RemoteException {
		return calculPourInt(monKaAMoi, N, n);
	}
	
	public static float calculPourInt(int k, int N, int n){
		float l = (float) 0;
		int indiceDebut = k*n/N + 1;
		int indiceFin = (k+1)*n/N;
		for(int i = indiceDebut; i <= indiceFin; i++) {
			l = (float) (l + 4/(n*(1 + ((i - 0.5)/n)*((i - 0.5)/n))));
		}
		return l;
	}
}
